<template>
  <el-row :gutter="24" class="panel-group" style="margin:0">
    <el-col :xs="24" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-money">
          <i class="iconfont icon-duankai card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            接入终端
          </div>
          <count-to :start-val="0" :end-val="data.OnlineCount" style="color:#67C23A" :duration="2600" class="card-panel-num" />
          <span>/</span>
          <count-to :start-val="0" :end-val="data.OfflineCount" :duration="2600" class="card-panel-num" />
        </div>
      </div>
    </el-col>
    <el-col :xs="24" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-message">
          <i class="iconfont icon-jiasu card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            文件同步数量
          </div>
          <count-to :start-val="0" :end-val="data.TodayFileOptLogCount" :duration="3000" class="card-panel-num" />
        </div>
      </div>
    </el-col>
    <el-col :xs="24" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-people">
          <i class="iconfont icon-anquandunpai card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            数据库同步
          </div>
          <count-to :start-val="0" :end-val="data.TodayBackupDBCount" :duration="3200" class="card-panel-num" />
        </div>
      </div>
    </el-col>
    <!-- <el-col :xs="24" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-people">
          <i class="iconfont icon-lianjie card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            转储版本
          </div>
          <count-to :start-val="0" :end-val="TodayDumpLogCount" :duration="3200" class="card-panel-num" />
        </div>
      </div>
    </el-col> -->
    <el-col :xs="24" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-shopping">
          <i class="iconfont icon-shuliangbiandongtongji card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            操作系统备份
          </div>
          <count-to :start-val="0" :end-val="data.TodayBackupSystemCount" :duration="3600" class="card-panel-num" />
        </div>
      </div>
    </el-col>
    <el-col :xs="24" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-shopping">
          <i class="iconfont icon-shuliangbiandongtongji card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            恶意代码文件
          </div>
          <count-to :start-val="0" :end-val="data.TodayVirusLogCount" :duration="3600" class="card-panel-num" />
        </div>
      </div>
    </el-col>
    <el-col :xs="24" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel2" style="flex-flow:row-reverse;padding-right:0">
        <el-button @click="parameterClick" style="text-align:right">首页参数</el-button>
      </div>
    </el-col>
    <!-- 首页参数 -->
    <el-dialog title="首页参数" :visible.sync="centerDialogVisible"  width="40%" @close='closeDialog' :close-on-press-escape = false  :close-on-click-modal = false >
        <el-form :model="ruleForm" ref="ruleForm" :rules="rules" label-width="30%">
            <!-- <el-card shadow="never" class="border-none margin-t24"> -->
                <el-row :gutter="24">
                    <el-col :sm="24" :md="24" :lg="24">
                        <el-form-item  label="数据统计最近：" prop="SumDays">
                            <el-input  size="small" auto-complete="off" style="width:70%" v-model.number="ruleForm.SumDays"><span slot="append">天</span></el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :sm="24" :md="24" :lg="24">
                        <el-form-item  label="事件严重性等级：" prop="EventLevel">
                            <el-select  size="small" v-model="ruleForm.EventLevel" style="width:70%" placeholder="请选择">
                              <el-option :value="0" label="全部"/>
                              <el-option :value="1" label="致命"/>
                              <el-option :value="2" label="紧急"/>
                              <el-option :value="3" label="重要"/>
                              <el-option :value="4" label="监视"/>
                              <el-option :value="5" label="普通"/>
                              <el-option :value="6" label="通知"/>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :sm="24" :md="24" :lg="24">
                        <el-form-item  label="事件显示条数：" prop="PageLength">
                            <el-input  size="small" auto-complete="off" style="width:70%" v-model.number="ruleForm.PageLength"><span slot="append">条</span></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            <!-- </el-card> -->
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button  size="small" class="newadd" type="primary" @click="determineClick('ruleForm')">确 定</el-button>
            <el-button  size="small" class="newadd"  @click="cancelClick()">取 消</el-button>
        </span>
    </el-dialog>
  </el-row>


</template>

<script>
import { GetShadowURLSumGroupByAccessType, GetEventLog, connrequest } from '@/api/firstPage.js'
import { getNowDay } from '@/utils/index.js'
// import {  } from '@/api/firstPage.js'
import CountTo from 'vue-count-to'

export default {
  data(){
    return{
      // TodayDumpLogCount: 0,
      // TodayFileOptLogCount: 0,
      // TodayBackupDBCount: 0,
      // TodayBackupSystemCount: 0,
      // OfflineCount:0,
      // OnlineCount:0,
      // TodayVirusLogCount:0,
      centerDialogVisible:false,
      ruleForm:{
        EventLevel:0,
        PageLength:0,
        SumDays:0
      },
      rules:{
        EventLevel:[{ required: true, message:'请选择严重等级', trigger:"change" }],
        PageLength:[{ required: true, message:'请输入显示条数', trigger:"blur" }],
        SumDays:[{ required: true, message:'请输入天数', trigger:"blur" }]
      }
    }
  },
  props:{
    data:{
      type:Object
    }
  },
  components: {
    CountTo
  },
  created() {
    console.log(this.data);
    // this.getData()
    // this.GetEventLog()
  },
  methods: {
    async getData(){
      const res = await connrequest('GetFirstPage')
      // console.log(res);
      // TodayFileOptLogCount
      this.TodayVirusLogCount = res.Data.TodayVirusLogCount //恶意代码文件数量
      this.OfflineCount = res.Data.OfflineCount
      this.OnlineCount = res.Data.OnlineCount
      this.TodayBackupDBCount = res.Data.TodayBackupDBCount //数据库
      this.TodayFileOptLogCount = res.Data.TodayFileOptLogCount //文件同步
      this.TodayBackupSystemCount = res.Data.TodayBackupSystemCount //操作系统
      this.TodayDumpLogCount =  res.Data.TodayDumpLogCount// 转储版本
      // console.log(this.BackupList,111111111);
    },
    // async getData(){
    //   let NowDay = getNowDay('time')
    //   const data = {
    //     Filter: {
    //       StartTime: NowDay,
    //       EndTime: ""
    //     }
    //   }
    //   const res = await GetShadowURLSumGroupByAccessType(data)
    //   if(res.Data){
    //     let block = res.Data.filter(item => { return item.ClassID === 1})
    //     let accelerate = res.Data.filter(item => { return item.ClassID === 2})
    //     let passThrough = res.Data.filter(item => { return item.ClassID === 3})
    //     this.block = block.length > 0 ? block[0].Count * 1 : 0
    //     this.accelerate = accelerate.length > 0 ? accelerate[0].Count * 1 : 0
    //     this.passThrough = passThrough.length > 0 ? passThrough[0].Count * 1 : 0
    //   }
    // },
    async GetEventLog() {
      let NowDay = getNowDay('time')
      const data = {
        Paging: {
          QueryPageNo: 1,
          QueryPageLength: 10
        },
        Filter: {
          StartTime: NowDay,
          EndTime: ""
        }
      }
      const res = await GetEventLog(data)
      this.eventNum = res.Paging.TotalCount
    },
    async parameterClick(){
      this.centerDialogVisible = true;
      const res = await connrequest('GetParamFirstPage')
      this.ruleForm = res.Data;

    },
    closeDialog(){
      this.$refs['ruleForm'].resetFields();
    },
    async determineClick(formName){
      this.$refs[formName].validate(async(valid) => {
        if (valid) {
          const data = {
            Data:this.ruleForm
          }
          const res = await connrequest('SetParamFirstPage',data)
          this.centerDialogVisible = false;
          this.$message.success('修改成功');
        }
      })
    },
    cancelClick(){
      this.centerDialogVisible = false;
      this.$nextTick(() => {
          this.$refs['ruleForm'].resetFields();
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  .card-panel-col {
    margin-bottom: 16px;
  }
  .card-panel2{
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    cursor: pointer;

    position: relative;
    overflow: hidden;
    color: #666;
  }
  .card-panel {
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 20px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);
    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #a834bf
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #a834bf
    }

    .card-panel-icon-wrapper {
      float: left;
      padding: 5px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 20px;
    }

    .card-panel-description {
      height: 40px;
      display: flex;
      align-items: center;
      font-weight: bold;
      margin: 5px;
      // margin-left: 0px;
      .card-panel-text {
        line-height: 14px;
        margin-right: 15px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 18px;
      }
      .card-panel-num {
        font-size: 18px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
// @media only screen and (min-width: 1200px) {
//   .el-col-lg-4-8 {
//     width: 20%;
//   }
//   .el-col-lg-offset-4-8 {
//     margin-left: 20%;
//   }
//   .el-col-lg-pull-4-8 {
//     position: relative;
//     right: 20%;
//   }
//   .el-col-lg-push-4-8 {
//     position: relative;
//     left: 20%;
//   }
// }
// @media only screen and (min-width: 1920px) {
//   .el-col-xl-4-8 {
//     width: 20%;
//   }
//   .el-col-xl-offset-4-8 {
//     margin-left: 20%;
//   }
//   .el-col-xl-pull-4-8 {
//     position: relative;
//     right: 20%;
//   }
//   .el-col-xl-push-4-8 {
//     position: relative;
//     left: 20%;
//   }
// }
// </style>
